<?php

/**
 * This is the model class for table "landlord".
 *
 * The followings are the available columns in table 'landlord':
 * @property integer $id
 * @property string $CompanyName
 * @property string $StreetAddress
 * @property string $SecondLineAddress
 * @property string $City
 * @property string $State
 * @property string $ZipCode
 * @property string $PhoneNumber
 * @property string $FaxNumber
 * @property string $EmailAddress
 * @property string $SoftwareTitle
 * @property integer $NumberProperties
 * @property string $PayPalAccountAddress
 * @property integer $iduser
 *
 * The followings are the available model relations:
 * @property User $iduser0
 * @property Managmentincludeinreport[] $managmentincludeinreports
 * @property Paymentinformation[] $paymentinformations
 * @property Rentalproperty[] $rentalproperties
 * @property Sitemanager[] $sitemanagers
 */
class Landlord extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Landlord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'landlord';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('NumberProperties, iduser', 'numerical', 'integerOnly'=>true),
			array('CompanyName, StreetAddress, SecondLineAddress, City, EmailAddress, PayPalAccountAddress', 'length', 'max'=>45),
			array('State', 'length', 'max'=>2),
			array('ZipCode', 'length', 'max'=>10),
			array('PhoneNumber, FaxNumber', 'length', 'max'=>12),
			array('SoftwareTitle', 'length', 'max'=>15),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, CompanyName, StreetAddress, SecondLineAddress, City, State, ZipCode, PhoneNumber, FaxNumber, EmailAddress, SoftwareTitle, NumberProperties, PayPalAccountAddress, iduser', 'safe', 'on'=>'search'),
			array('CompanyName, StreetAddress, City, State, PayPalAccountAddress, PhoneNumber','required'),
			array('EmailAddress', 'email'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'iduser0' => array(self::BELONGS_TO, 'User', 'iduser'),
			'managmentincludeinreports' => array(self::HAS_MANY, 'Managmentincludeinreport', 'idmanagement'),
			'paymentinformations' => array(self::HAS_MANY, 'Paymentinformation', 'idManagement'),
			'rentalproperties' => array(self::HAS_MANY, 'Rentalproperty', 'idManagement'),
			'sitemanagers' => array(self::HAS_MANY, 'Sitemanager', 'idManagement'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'CompanyName' => 'Company Name',
			'StreetAddress' => 'Street Address',
			'SecondLineAddress' => 'Second Line Address',
			'City' => 'City',
			'State' => 'State',
			'ZipCode' => 'Zip Code',
			'PhoneNumber' => 'Phone Number',
			'FaxNumber' => 'Fax Number',
			'EmailAddress' => 'Email Address',
			'SoftwareTitle' => 'Software Title',
			'NumberProperties' => 'Number Of Properties',
			'PayPalAccountAddress' => 'Pay Pal Account Address',
			'iduser' => 'Iduser',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('CompanyName',$this->CompanyName,true);
		$criteria->compare('StreetAddress',$this->StreetAddress,true);
		$criteria->compare('SecondLineAddress',$this->SecondLineAddress,true);
		$criteria->compare('City',$this->City,true);
		$criteria->compare('State',$this->State,true);
		$criteria->compare('ZipCode',$this->ZipCode,true);
		$criteria->compare('PhoneNumber',$this->PhoneNumber,true);
		$criteria->compare('FaxNumber',$this->FaxNumber,true);
		$criteria->compare('EmailAddress',$this->EmailAddress,true);
		$criteria->compare('SoftwareTitle',$this->SoftwareTitle,true);
		$criteria->compare('NumberProperties',$this->NumberProperties);
		$criteria->compare('PayPalAccountAddress',$this->PayPalAccountAddress,true);
		$criteria->compare('iduser',$this->iduser);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
	
	 public function afterDelete()
	  {
		parent::afterDelete();
		User::model()->deleteByPk($this->iduser); //field value you want to access
	  }
}